<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/31 0031
 * Time: 下午 1:27
 */
header("Content-type:text/html;charset=utf-8");
header("Access-Control-Allow-Origin:*");

if(!empty($_POST) && $_POST["uname"]!=null && $_POST["upwd"]!=null){

    $uname = $_POST["uname"];
    $upwd = $_POST["upwd"];



    $connection = new mysqli("127.0.0.1","root","","mytps138");

    mysqli_query($connection,"set names utf8");
//    print_r($connection->connect_error);

    //先判断是否帐号是否存在;
    $sqlN = "SELECT*FROM userinfo WHERE uemail = '".$uname."'";

    $res1 = $connection->query($sqlN);
//    print_r($res1);


    if($res1->num_rows == 1){
        //账号存在；
//        写sql语句；
        $sql = "SELECT*FROM userinfo WHERE uemail = '".$uname."' AND upwd = '".$upwd."'";

        $res = $connection->query($sql);

//        print_r($res);

        if ($res->num_rows == 1){
            //帐号密码正确

            //查询用户的ID；
            $cook = 'SELECT*FROM userinfo WHERE uemail = "'.$uname.'"';

            $result = $connection->query($cook);

            //转成数组;
            $row = $result->fetch_assoc();

            $arr = array("status"=> 1,"uid"=>$row["uid"]);
            print_r(json_encode($arr));
        }
        if($res->num_rows == 0){
            //密码不正确；
            $arr = array("status"=>0);
            print_r(json_encode($arr));
        }

    }
    //帐号不存在；
    if ($res1->num_rows == 0){
        $arr1 = array("status" => 3);
        print_r(json_encode($arr1));
    }

}

$connection->close();